﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: FZH
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;
using FriendStar.Domain.Entity.SystemManage;
using FriendStar.Domain.IRepository.SystemManage;
using FriendStar.Repository.SystemManage;

namespace FriendStar.Application.SystemManage
{
    /// <summary>
	/// 数据表 Sys_RunParam 对应的数据应用功能类。
	/// </summary>
	public class Sys_RunParamApp
    {       
        private string UseUnit = Configs.GetValue("UseUnit");
        private string FFacNum = Configs.GetValue("FactoryFlag"); 

        private ISys_RunParamRepository service = new Sys_RunParamRepository();

        public List<Sys_RunParamEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<Sys_RunParamEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.ParamID == keyword);
            }
            return service.FindList(expression, pagination);
        }

        public Sys_RunParamEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.ParamID == keyValue);
        }

        public void SubmitForm(Sys_RunParamEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.FUpdateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FUpdateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FUpdateTime = DateTime.Now.ToString("HH:mm:ss");
                service.Update(entity);
            }
            else
            {
                entity.ParamID = Common.GuId();
                entity.UseUnit = UseUnit;
                entity.FFacNum = FFacNum;
                entity.FCreateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FCreateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FCreateTime = DateTime.Now.ToString("HH:mm:ss");
                entity.FUpdateBy = OperatorProvider.Provider.GetCurrent().UserName;
                entity.FUpdateDate = DateTime.Now.ToString("yyyy-MM-dd");
                entity.FUpdateTime = DateTime.Now.ToString("HH:mm:ss");
                service.Insert(entity);
            }
        }

        public void FastInsert(string TypeNum, string ItemParam, string ItemDesc, string ItemDouDate, string ItemStates)
        {
            Sys_RunParamEntity entity = new Sys_RunParamEntity();
            entity.FTypeNum = TypeNum;
            entity.FItemParam = ItemParam;
            entity.FItemDesc = ItemDesc;
            entity.FItemDouDate = ItemDouDate;
            entity.FItemStates = ItemStates;
            SubmitForm(entity, "");
        }
    }
}